<template>
  <div class="system-role-page">
    <el-card class="role-card">
      <template #header>
        <div class="card-header">
          <span>角色管理</span>
          <el-button type="primary" @click="handleAdd" v-if="hasPerm('system:role:add')">新增角色</el-button>
        </div>
      </template>
      
      <el-table :data="roleList" style="width: 100%">
        <el-table-column prop="roleCode" label="角色编码" width="120" />
        <el-table-column prop="roleName" label="角色名称" width="150" />
        <el-table-column prop="description" label="描述" width="200" />
        <el-table-column prop="status" label="状态" width="100">
          <template #default="scope">
            <el-tag :type="scope.row.status === 'active' ? 'success' : 'danger'">
              {{ scope.row.status === 'active' ? '启用' : '禁用' }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="200">
          <template #default="scope">
            <el-button size="small" @click="handleView(scope.row)" v-if="hasPerm('system:role:view')">查看</el-button>
            <el-button size="small" type="primary" @click="handleEdit(scope.row)" v-if="hasPerm('system:role:edit')">编辑</el-button>
            <el-button size="small" type="danger" @click="handleDelete(scope.row)" v-if="hasPerm('system:role:delete')">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { hasPerm } from '@/utils/permission'
import { ElMessage } from 'element-plus'

const roleList = ref([])

const handleAdd = () => {
  ElMessage.info('新增角色功能')
}

const handleView = (row) => {
  ElMessage.info(`查看角色：${row.roleCode}`)
}

const handleEdit = (row) => {
  ElMessage.info(`编辑角色：${row.roleCode}`)
}

const handleDelete = (row) => {
  ElMessage.info(`删除角色：${row.roleCode}`)
}

onMounted(() => {
  // 模拟数据
  roleList.value = [
    {
      roleCode: 'admin',
      roleName: '系统管理员',
      description: '拥有所有权限',
      status: 'active'
    },
    {
      roleCode: 'manager',
      roleName: '部门经理',
      description: '部门管理权限',
      status: 'active'
    },
    {
      roleCode: 'user',
      roleName: '普通用户',
      description: '基础操作权限',
      status: 'active'
    }
  ]
})
</script>

<style scoped>
.system-role-page {
  padding: 20px;
}

.role-card {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style> 